|
RAIS
3.2
|
00001 using System; 00002 using System.Data; 00003 using System.Configuration; 00004 using System.Collections; 00005 using System.Collections.Generic; 00006 using System.Web; 00007 using System.Linq; 00008 using System.Web.Security; 00009 using System.Web.UI; 00010 using System.Web.UI.WebControls; 00011 using System.Web.UI.WebControls.WebParts; 00012 using System.Web.UI.HtmlControls; 00013 00014 using RAIS.Common.UserManagement; 00015 using RAIS.UI.Common; 00016 00017 using FunctionRoleCategories = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.FunctionRole.Category>; 00018 using FunctionRoleSubcategories = System.Collections.Generic.Dictionary<string, RAIS.Common.UserManagement.FunctionRole.Subcategory>; 00019 00020 namespace RAIS.UI.SpecificMasks 00021 { 00025 public partial class CustomNodes_New : System.Web.UI.Page 00026 { 00027 //********************************************************************* 00028 #region Event handlers 00029 protected void Page_PreLoad(object sender, EventArgs e) 00030 { 00031 RAIS.UI.Common.PageManagement.TrimTextBoxValues(this); 00032 } 00039 protected void Page_Load(object sender, EventArgs e) 00040 { 00041 this.Response.Cache.SetNoStore(); 00042 if (this.CurrentUser == null) 00043 UI.Common.AccessManagement.SignOut(this); 00044 00045 this.LBLresult.Text = string.Empty; 00046 if (!this.IsPostBack) 00047 { 00048 this.LBLusernameNoTranslation.Text = this.CurrentUser.Name; 00049 this.BTNdelete.Attributes.Add("onclick", string.Format("javascript: return confirm('{0}');", RAIS.Common.Messages.DELETE_QUESTION_NODE.Replace("'", "\\'"))); 00050 00051 UI.Common.TableManagement.InitializeCategoryList(this.DDLcategory); 00052 UI.Common.TableManagement.InitializeSubcategoryListBoxByCategory(this.LBsubcategory, this.SelectedCategory); 00053 this.LBsubcategory.SelectedIndex = 0; 00054 this.LBLadmin.ForeColor = RAIS.UI.Common.Constants.COLOR_OF_MENU_BAR_TEXT_HIGHLIGHT; 00055 this.CurrentFormMode = DynamicMaskManagement.FormMode.View; 00056 this.SetControlsProperties(); 00057 00058 UI.Common.PageManagement.InitializePage(this, this.TreeView1); 00059 // this.LBTNmessagebox.Visible = !(this.CurrentUser.FunctionalRole.Type == FunctionRole.FunctionRoleType.Guest); 00060 } 00061 PageManagement.InitHelpMainMenu(LBTNdefault); 00062 } 00069 protected void Page_Init(object sender, EventArgs e) 00070 { 00071 PageManagement.SetScrolableListBox(LBsubcategory, this, true); 00072 } 00079 protected void DDLcategory_SelectedIndexChanged(object sender, EventArgs e) 00080 { 00081 UI.Common.TableManagement.InitializeSubcategoryListBoxByCategory(this.LBsubcategory, this.SelectedCategory); 00082 Subcategories = RAIS.ApplicationLogicLayer.UserManagement.GetFunctionalRoleSubcategories(this.SelectedCategory, false) 00083 .Select(x=>x.Value) 00084 .ToList(); 00085 this.LBsubcategory.SelectedIndex = 0; 00086 this.SetControlsProperties(); 00087 } 00094 protected void BTNadd_Click(object sender, EventArgs e) 00095 { 00096 this.TXTnodename.Text = string.Empty; 00097 this.CurrentFormMode = DynamicMaskManagement.FormMode.Add; 00098 this.SetControlsProperties(); 00099 } 00106 protected void BTNedit_Click(object sender, EventArgs e) 00107 { 00108 this.TXTnodename.Text = this.LBsubcategory.SelectedValue; 00109 this.CurrentFormMode = DynamicMaskManagement.FormMode.Edit; 00110 this.SetControlsProperties(); 00111 } 00118 protected void BTNdelete_Click(object sender, EventArgs e) 00119 { 00120 string returnMessage = string.Empty; 00121 bool success = false; 00122 00123 int selectedIndex = this.LBsubcategory.SelectedIndex; 00124 success = RAIS.ApplicationLogicLayer.UserManagement.RemoveSubcategory( 00125 this.SelectedSubcategory.ID 00126 , ref returnMessage); 00127 00128 if (success) 00129 { 00130 UI.Common.TableManagement.InitializeSubcategoryListBoxByCategory(this.LBsubcategory, this.SelectedCategory); 00131 selectedIndex = (selectedIndex >= this.LBsubcategory.Items.Count) 00132 ? this.LBsubcategory.Items.Count - 1 00133 : selectedIndex; 00134 if (selectedIndex != -1) 00135 this.LBsubcategory.Items[selectedIndex].Selected = true; 00136 } 00137 00138 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00139 returnMessage, 00140 success); 00141 } 00148 protected void BTNundo_Click(object sender, EventArgs e) 00149 { 00150 this.CurrentFormMode = DynamicMaskManagement.FormMode.View; 00151 this.SetControlsProperties(); 00152 } 00159 protected void BTNapply_Click(object sender, EventArgs e) 00160 { 00161 string returnMessage = string.Empty; 00162 bool success = false; 00163 00164 FunctionRole.Subcategory subcategory = null; 00165 if (this.CurrentFormMode == DynamicMaskManagement.FormMode.Edit) 00166 subcategory = this.SelectedSubcategory; 00167 00168 subcategory = this.GetSubcategoryObjectFromControls(subcategory); 00169 00170 if (this.CurrentFormMode == DynamicMaskManagement.FormMode.Add) 00171 { 00172 success = RAIS.ApplicationLogicLayer.UserManagement.AddSubcategory( 00173 subcategory 00174 , ref returnMessage); 00175 } 00176 else 00177 { 00178 success = RAIS.ApplicationLogicLayer.UserManagement.SaveSubcategory( 00179 subcategory 00180 , ref returnMessage); 00181 } 00182 00183 if (success) 00184 { 00185 int currentIndex = this.LBsubcategory.SelectedIndex; 00186 UI.Common.TableManagement.InitializeSubcategoryListBoxByCategory(this.LBsubcategory, this.SelectedCategory); 00187 if (this.CurrentFormMode == DynamicMaskManagement.FormMode.Add) 00188 this.LBsubcategory.SelectedIndex = this.LBsubcategory.Items.Count - 1; 00189 else 00190 this.LBsubcategory.SelectedIndex = currentIndex; 00191 this.CurrentFormMode = DynamicMaskManagement.FormMode.View; 00192 this.SetControlsProperties(); 00193 } 00194 00195 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00196 returnMessage, 00197 success); 00198 } 00205 protected void BTNup_Click(object sender, EventArgs e) 00206 { 00207 this.ChangeOrder(true); 00208 } 00215 protected void BTNdown_Click(object sender, EventArgs e) 00216 { 00217 this.ChangeOrder(false); 00218 } 00224 protected void LBsubcategory_SelectedIndexChanged(object sender, EventArgs e) 00225 { 00226 this.SetControlsProperties(); 00227 //this.EnableUpDownButtons(); 00228 this.SetFocus(this.LBsubcategory); 00229 } 00236 protected void LBTNlogout_Click(object sender, EventArgs e) 00237 { 00238 UI.Common.AccessManagement.SignOut(this); 00239 } 00246 protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) 00247 { 00248 UI.Common.UserManagement.ProcessTreeViewOnRedirect(this.TreeView1); 00249 } 00250 #endregion Event handlers 00251 //********************************************************************* 00252 #region Private Methods 00253 00259 protected void ChangeOrder(bool isUp) 00260 { 00261 string returnMessage = string.Empty; 00262 bool success = true; 00263 FunctionRole.Subcategory currentSubcategory = this.SelectedSubcategory; 00264 00265 00266 int newIndex = isUp ? 00267 Subcategories.Where(x=>x.Order<currentSubcategory.Order) 00268 .Select(x=>x.Order) 00269 .DefaultIfEmpty(currentSubcategory.Order) 00270 .Max(x => x) : 00271 Subcategories.Where(x=>x.Order>currentSubcategory.Order) 00272 .Select(x => x.Order) 00273 .DefaultIfEmpty(currentSubcategory.Order) 00274 .Min(x => x); 00275 00276 if (newIndex != currentSubcategory.Order) 00277 { 00278 currentSubcategory.Order = newIndex; 00279 success = ApplicationLogicLayer.UserManagement.SaveSubcategoryOrder(currentSubcategory, ref returnMessage); 00280 if (success) 00281 { 00282 this.LBsubcategory.Items.Clear(); 00283 UI.Common.TableManagement.InitializeSubcategoryListBoxByCategory(this.LBsubcategory, this.SelectedCategory); 00284 00285 this.LBsubcategory.Items.FindByText(currentSubcategory.Name).Selected = true; 00286 this.EnableUpDownButtons(); 00287 } 00288 else 00289 { 00290 RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, 00291 returnMessage, 00292 success); 00293 } 00294 } 00295 } 00299 private void EnableUpDownButtons() 00300 { 00301 this.BTNup.Enabled = (this.CurrentFormMode == DynamicMaskManagement.FormMode.View && this.LBsubcategory.SelectedIndex > 0); 00302 this.BTNdown.Enabled = (this.CurrentFormMode == DynamicMaskManagement.FormMode.View && this.LBsubcategory.SelectedIndex < this.LBsubcategory.Items.Count - 1); 00303 } 00310 FunctionRole.Subcategory GetSubcategoryObjectFromControls(FunctionRole.Subcategory subcategory) 00311 { 00312 if (subcategory == null) 00313 subcategory = new FunctionRole.Subcategory(); 00314 00315 subcategory.Name = this.TXTnodename.Text; 00316 subcategory.Parent = this.SelectedCategory; 00317 00318 return subcategory; 00319 } 00323 void SetControlsProperties() 00324 { 00325 switch (this.CurrentFormMode) 00326 { 00327 case DynamicMaskManagement.FormMode.View: 00328 this.LBLmenu.Enabled = true; 00329 this.DDLcategory.Enabled = true; 00330 this.LBsubcategory.Enabled = true; 00331 this.LBLnodename.Visible = false; 00332 this.TXTnodename.Visible = false; 00333 this.RFVnodename.Enabled = this.TXTnodename.Visible; 00334 this.RFVnodename.Visible = this.RFVnodename.Enabled; 00335 00336 this.BTNadd.Enabled = true; 00337 this.BTNedit.Enabled = true; 00338 this.BTNdelete.Enabled = this.SelectedSubcategory.CustomSubcategory; 00339 this.BTNundo.Enabled = false; 00340 this.BTNapply.Enabled = false; 00341 00342 this.SetFocus(this.LBsubcategory); 00343 break; 00344 00345 case DynamicMaskManagement.FormMode.Edit: 00346 case DynamicMaskManagement.FormMode.Add: 00347 this.LBLmenu.Enabled = false; 00348 this.DDLcategory.Enabled = false; 00349 this.LBsubcategory.Enabled = false; 00350 this.LBLnodename.Visible = true; 00351 this.TXTnodename.Visible = true; 00352 this.RFVnodename.Enabled = this.TXTnodename.Visible; 00353 this.RFVnodename.Visible = this.RFVnodename.Enabled; 00354 00355 this.BTNadd.Enabled = false; 00356 this.BTNedit.Enabled = false; 00357 this.BTNdelete.Enabled = false; 00358 this.BTNundo.Enabled = true; 00359 this.BTNapply.Enabled = true; 00360 00361 this.SetFocus(this.TXTnodename); 00362 break; 00363 } 00364 00365 this.EnableUpDownButtons(); 00366 UI.Common.UserManagement.EnableCommonControls(this, !this.EditMode); 00367 } 00368 #endregion Private Methods 00369 //********************************************************************* 00370 #region Private properties 00371 00374 protected UserData CurrentUser 00375 { 00376 get { return (UserData)this.Session[UI.Common.Constants.CURRENT_USER_TAG]; } 00377 } 00381 private FunctionRole.Category SelectedCategory 00382 { 00383 get 00384 { 00385 FunctionRoleCategories categories = RAIS.ApplicationLogicLayer.UserManagement.FunctionalRoleCategories; 00386 if (categories != null && categories.ContainsKey(this.DDLcategory.SelectedValue)) 00387 return categories[this.DDLcategory.SelectedValue]; 00388 else 00389 return null; 00390 } 00391 } 00395 private FunctionRole.Subcategory SelectedSubcategory 00396 { 00397 get 00398 { 00399 FunctionRoleSubcategories subcategories = RAIS.ApplicationLogicLayer.UserManagement.GetFunctionalRoleSubcategories(this.SelectedCategory, false); 00400 if (subcategories != null && subcategories.ContainsKey(this.LBsubcategory.SelectedValue)) 00401 return subcategories[this.LBsubcategory.SelectedValue]; 00402 else 00403 return null; 00404 } 00405 } 00409 protected DynamicMaskManagement.FormMode CurrentFormMode 00410 { 00411 get 00412 { 00413 return (DynamicMaskManagement.FormMode)(ViewState["currentFormMode"]); 00414 } 00415 set 00416 { 00417 ViewState.Add("currentFormMode", value); 00418 } 00419 } 00423 public List<FunctionRole.Subcategory> Subcategories 00424 { 00425 get { return Session["CurentSubcategories"] as List<FunctionRole.Subcategory>; } 00426 set {Session["CurentSubcategories"] = value;} 00427 } 00428 bool EditMode 00429 { 00430 get 00431 { 00432 return (this.CurrentFormMode == DynamicMaskManagement.FormMode.Edit 00433 || this.CurrentFormMode == DynamicMaskManagement.FormMode.Add); 00434 } 00435 } 00436 #endregion Private properties 00437 } 00438 }